package com.cloud.entity;

import com.alibaba.fastjson.JSONObject;
import com.cloud.util.CommonUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Henry.Song
 * @version 2020/11/26
 * @description
 */
public class ConvertTaskEntity extends BasicConvertTaskEntity {

    public void setCoordPoints(List<PointEntity> coordPoints) {
        put("coordPoints", coordPoints);
    }

    public List<PointEntity> getCoordPoints() {

        if (getJSONArray("coordPoints") == null) {
            setCoordPoints(new ArrayList<PointEntity>());
        }

        List<PointEntity> pointEntities = new ArrayList<PointEntity>();
        for(Object object : getJSONArray("coordPoints").toArray()) {
            if (object instanceof PointEntity) {
                pointEntities.add((PointEntity)object);
            } else if (object instanceof Map) {
                PointEntity pointEntity = new PointEntity();
                CommonUtil.copyFromMap(pointEntity, (Map)object);
                pointEntities.add(pointEntity);
            }
        }
        return pointEntities;
    }

    public void setSkipCoordPoints(List<PointEntity> skipCoordPoints) {
        put("skipCoordPoints", skipCoordPoints);
    }

    public List<PointEntity> getSkipCoordPoints() {

        if (getJSONArray("skipCoordPoints") == null) {
            setSkipCoordPoints(new ArrayList<PointEntity>());
        }

        List<PointEntity> pointEntities = new ArrayList<PointEntity>();
        for(Object object : getJSONArray("skipCoordPoints").toArray()) {
            if (object instanceof PointEntity) {
                pointEntities.add((PointEntity)object);
            } else if (object instanceof Map) {
                PointEntity pointEntity = new PointEntity();
                CommonUtil.copyFromMap(pointEntity, (Map)object);
                pointEntities.add(pointEntity);
            }
        }
        return pointEntities;
    }

    public void setCacheNumber(int cacheNumber) {
        put("cacheNumber", cacheNumber);
    }

    public int getCacheNumber() {
        return getIntValue("cacheNumber");
    }
}
